<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%-- 设置上下文路径到作用域 --%>
<c:set var="ctx" scope="request" value="${pageContext.request.contextPath}" />
<html>
<head>
    <title>Title</title>
    <style>
        .box { width: 400px; text-align: center; margin:0px auto;}
        form,table { width: 100%; border:none; }
    </style>
</head>
<body>
<div class="box">
    <h1>添加昆虫信息</h1>
    <form id="addform" method="post" action="${ctx}/insect/save">
        <table border="0px">
            <tr>
                <td>昆虫名</td>
                <td>
                    <input name="name" id="name" type="text"/>
                </td>
            </tr>
            <tr>
                <td>昆虫寿命</td>
                <td>
                    <input name="life" id="life" type="text"/>
                </td>
            </tr>
            <tr>
                <td>地域分布</td>
                <td>
                    <input id="area" name="area"/>
                </td>
            </tr>
            <tr>
                <td>首次发现时间</td>
                <td>
                    <input type="date" id="discovery_time" name="discovery_time"/>
                </td>
            </tr>
            <tr>
                <td>所属分类</td>
                <td>
                    <select name="cid" id="cid">
                        <option value="0">--请选择分类--</option>
                        <c:forEach items="${categoryList}" var="category">
                            <option value="${category.id}">${category.cname}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="添加">
                </td>
            </tr>
        </table>
    </form>
</div>

<script src="${ctx}/statics/js/jquery.js"></script>
<script>
    $(function(){
        $("#addform").submit(function(){
            var name = $("#name").val();
            if (name == "") {
                alert("昆虫名不能为空!");
                return false;
            }
            return true;
        })
    })
</script>
</body>
</html>

